package ch2;

import java.util.*;

import ch1.Person;

public class Caculator {
	// 算加法
	// 1:算两个数的加法
	public int add(int a, int b) {
		return a + b;
	}

	// 三个的
	public int add(int a, int b, int c) {
		return a + b + c;
	}

	// 数组
	public int add(int[] ar) {
		return -1;
	}
	// 集成了数组的优点（），调用起来方便

	// 可变参数
	public int jia(int... a) {
		int sum = 0;
		for (int i = 0; i < a.length; i++) {
			sum += a[i];
		}
		return sum;
	}

	// 多个数的乘法
	public long multiply(int... a) {
		if (a.length == 0)
			return 0L;//
		long sum = 1;
		for (int i : a)
			sum *= i;
		return sum;
	}

	public static void main(String[] args) {
		Caculator c = new Caculator();
		int r1 = c.jia(1, 4, 5, 10, 40, 100, 4003, 49);
		System.out.println(r1);
		int r2 = c.jia(2, 5);
		System.out.println(r2);
		int r3 = c.jia(15);
		System.out.println(r3);
		int r4 = c.jia();
		System.out.println(r4);
		System.out.println(">>>>>>>>>>>>>>>>>>>");

		List<Person> li = new ArrayList<>();
		li.add(new Person("许鹏", 21, "男"));

		Collections.addAll(li, new Person("许鹏1", 21, "男"), new Person("许鹏4", 21, "男"), new Person("许鹏5", 21, "男"),
				new Person("许鹏2", 21, "男"), new Person("许鹏3", 21, "男"), new Person("许鹏", 21, "男"));
		// System.out.println(li);
		for (Person p : li)
			System.out.println(p);
	}
}
